{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "<div style='text-align : center;'>\n",
    "<h2>高德API：API调用代码封装成函数</h2>\n",
    "=============================================\n",
    "</div>\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* `key` 高德开放平台.控制台--我的应用--创建新应用--网络服务--填入关键名称会自动生成键key\n",
    "* `url` 高德开放平台.首页--开发支持>Web服务API\n",
    "* 需要的函数模块：`requests` , `json`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 地理编码\n",
    "``` python\n",
    "def geocode(address,city=None,batch=None,sig=None)->dict:\n",
    "    '''获取地理编码'''\n",
    "    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'\n",
    "    params = {\n",
    "        'key':key_chen,\n",
    "        'address':address,\n",
    "        'city':city,\n",
    "        'batch':batch,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data \n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| address | 结构化地址信息 | 如：北京市朝阳区阜通东大街6号。多个地址请用\"|\"进行间隔，batch=true |\n",
    "| batch | 批量查询控制 | true or false |\n",
    "| url |  API 服务地址 | 不同服务url不同 |\n",
    "| sig | 数字签名 |  |\n",
    "| params | 返回的参数 |  |\n",
    "| key | ”Web服务API”密钥 |  |\n",
    "| output | 返回数据格式类型 | json/xml,当output 参数为json时可以调用函数 |\n",
    "\n",
    "\n",
    "-----------------\n",
    "-----------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 路径规划-步行路径规划\n",
    "\n",
    "``` python\n",
    "def walking(origin,destination,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/direction/walking?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'origin':origin,\n",
    "        'destination':destination,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "```\n",
    "\n",
    "* 注意：<u>调用函数时，实参为 `origin和destination的地理编码` </u> \n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| origin | 出发点 |  |\n",
    "| destination | 目的地 |  |\n",
    "\n",
    "------------------\n",
    "----------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 行政区域查询\n",
    "\n",
    "```python\n",
    "def district(keywords,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/config/district?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'keywords':keywords,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| keywords | 查询关键字 | 搜索关键词支持：行政区名称、citycode、adcode |\n",
    "\n",
    "-----------------------------------------------\n",
    "------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 搜索POI-关键字搜索\n",
    "> 四种筛选机制:关键字搜索、周边搜索、多边形搜索、ID查询\n",
    "\n",
    "```python\n",
    "def place(keywords,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/place/text?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'keywords':keywords,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "```\n",
    "* place建议使用`adcode`\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| keywords | 查询关键字 | 搜索关键词支持：行政区名称、citycode、adcode |\n",
    "| types | 查询POI类型 |    可选值：分类代码 或 汉字（若用汉字，请严格按照附件之中的汉字填写） |\n",
    "| location | 中心点坐标 | 周边搜索 |\n",
    "| polygon | 经纬度坐标对 | 多边形搜索 |\n",
    "| id | 兴趣点ID | ID查询 |\n",
    "\n",
    "-----------------------------------------------\n",
    "------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### IP定位\n",
    "> 根据用户输入的IP地址，能够快速的帮用户定位IP的所在位置。\n",
    "\n",
    "```python\n",
    "def ip(ip,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/ip?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'ip':ip,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "```\n",
    "\n",
    "----------------------------\n",
    "-----------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 静态地图\n",
    "\n",
    "```python\n",
    "from PIL import Image\n",
    "from io import BytesIO\n",
    "def staticmap(location,zoom,size=None,scale=1,markers=None,labels=None,paths=None,traffic=0,page=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/staticmap?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'location':location,\n",
    "        'zoom':zoom,\n",
    "        'size':size,\n",
    "        'scale':scale,\n",
    "        'markers':markers,\n",
    "        'labels':labels,\n",
    "        'paths':paths,\n",
    "        'traffic':traffic,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = Image.open(BytesIO(response.content))\n",
    "    return data\n",
    "```\n",
    "* 系统marersStyle：label，font ,bold, fontSize，fontColor，background\n",
    "* 例：markers=size,color,lable-------->markers=mid,0xFF0000,A:116.37359,39.92437;116.47359,39.92437\n",
    "* 【调用格式】：zdnf_map = staticmap(location='113.679287,23.632575', zoom=12)\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| zoom | 地图级别 | 地图缩放级别:[1,17],级别越大，地理名越具体 |\n",
    "| size | 地图大小 |  |\n",
    "| scale | 普通/高清 |  |\n",
    "| markers | 标注 |  markers=markersStyle1:location1;location2..|markersStyle2: |\n",
    "| labels | 标签 |  |\n",
    "| paths | 折线 |  |\n",
    "| traffic | 交通路况标识 |   |\n",
    "| color | 颜色 | \t选值范围：[0x000000, 0xffffff] |\n",
    "\n",
    "----------------------------------------------------------------------------------------------------------------\n",
    "--------------------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 坐标转换\n",
    "> 能够将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标\n",
    "\n",
    "\n",
    "```python\n",
    "def tran(locations,coordsys,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/assistant/coordinate/convert?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'locations':locations,\n",
    "        'coordsys':'coordsys'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data    \n",
    "\n",
    "```\n",
    "* 【调用格式】：*_tran = tran(locations='',coordsys='')\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| coordsys | 原坐标系 | 原坐标系，可选值：gps;mapbar;baidu;autonavi |\n",
    "\n",
    "-------------------------------------------------------------------------------------------\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 天气查询\n",
    "> 根据用户输入的adcode，查询目标区域当前/未来的天气情况\n",
    "\n",
    "```python\n",
    "def weather(city,extensions)->dict:\n",
    "    url='https://restapi.amap.com/v3/weather/weatherInfo?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'city':city,\n",
    "        'extensions':'extensions'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data \n",
    "```\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| extensions | 气象类型 | 查询目标区域当前base/未来的天气情况all |\n",
    "| city | 城市编码 | 输入城市的adcode |\n",
    "\n",
    "【**adcode-城市编码查询**】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>中文名</th>\n",
       "      <th>adcode</th>\n",
       "      <th>citycode</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中华人民共和国</td>\n",
       "      <td>100000</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>北京市</td>\n",
       "      <td>110000</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>北京市市辖区</td>\n",
       "      <td>110100</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>东城区</td>\n",
       "      <td>110101</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>西城区</td>\n",
       "      <td>110102</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>朝阳区</td>\n",
       "      <td>110105</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>丰台区</td>\n",
       "      <td>110106</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>石景山区</td>\n",
       "      <td>110107</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>海淀区</td>\n",
       "      <td>110108</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>门头沟区</td>\n",
       "      <td>110109</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>房山区</td>\n",
       "      <td>110111</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>通州区</td>\n",
       "      <td>110112</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>顺义区</td>\n",
       "      <td>110113</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>昌平区</td>\n",
       "      <td>110114</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>大兴区</td>\n",
       "      <td>110115</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>怀柔区</td>\n",
       "      <td>110116</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>平谷区</td>\n",
       "      <td>110117</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>密云区</td>\n",
       "      <td>110118</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>延庆区</td>\n",
       "      <td>110119</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>天津市</td>\n",
       "      <td>120000</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>天津市市辖区</td>\n",
       "      <td>120100</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>和平区</td>\n",
       "      <td>120101</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>河东区</td>\n",
       "      <td>120102</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>河西区</td>\n",
       "      <td>120103</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>南开区</td>\n",
       "      <td>120104</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>河北区</td>\n",
       "      <td>120105</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>红桥区</td>\n",
       "      <td>120106</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>东丽区</td>\n",
       "      <td>120110</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>西青区</td>\n",
       "      <td>120111</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>津南区</td>\n",
       "      <td>120112</td>\n",
       "      <td>22.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3503</th>\n",
       "      <td>台湾省</td>\n",
       "      <td>710000</td>\n",
       "      <td>1886.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3504</th>\n",
       "      <td>香港特别行政区</td>\n",
       "      <td>810000</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3505</th>\n",
       "      <td>中西区</td>\n",
       "      <td>810001</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3506</th>\n",
       "      <td>湾仔区</td>\n",
       "      <td>810002</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3507</th>\n",
       "      <td>东区</td>\n",
       "      <td>810003</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3508</th>\n",
       "      <td>南区</td>\n",
       "      <td>810004</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3509</th>\n",
       "      <td>油尖旺区</td>\n",
       "      <td>810005</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3510</th>\n",
       "      <td>深水埗区</td>\n",
       "      <td>810006</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3511</th>\n",
       "      <td>九龙城区</td>\n",
       "      <td>810007</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3512</th>\n",
       "      <td>黄大仙区</td>\n",
       "      <td>810008</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3513</th>\n",
       "      <td>观塘区</td>\n",
       "      <td>810009</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3514</th>\n",
       "      <td>荃湾区</td>\n",
       "      <td>810010</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3515</th>\n",
       "      <td>屯门区</td>\n",
       "      <td>810011</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3516</th>\n",
       "      <td>元朗区</td>\n",
       "      <td>810012</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3517</th>\n",
       "      <td>北区</td>\n",
       "      <td>810013</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3518</th>\n",
       "      <td>大埔区</td>\n",
       "      <td>810014</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3519</th>\n",
       "      <td>西贡区</td>\n",
       "      <td>810015</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3520</th>\n",
       "      <td>沙田区</td>\n",
       "      <td>810016</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3521</th>\n",
       "      <td>葵青区</td>\n",
       "      <td>810017</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3522</th>\n",
       "      <td>离岛区</td>\n",
       "      <td>810018</td>\n",
       "      <td>1852.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3523</th>\n",
       "      <td>澳门特别行政区</td>\n",
       "      <td>820000</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3524</th>\n",
       "      <td>花地玛堂区</td>\n",
       "      <td>820001</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3525</th>\n",
       "      <td>花王堂区</td>\n",
       "      <td>820002</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3526</th>\n",
       "      <td>望德堂区</td>\n",
       "      <td>820003</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3527</th>\n",
       "      <td>大堂区</td>\n",
       "      <td>820004</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3528</th>\n",
       "      <td>风顺堂区</td>\n",
       "      <td>820005</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3529</th>\n",
       "      <td>嘉模堂区</td>\n",
       "      <td>820006</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3530</th>\n",
       "      <td>路凼填海区</td>\n",
       "      <td>820007</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3531</th>\n",
       "      <td>圣方济各堂区</td>\n",
       "      <td>820008</td>\n",
       "      <td>1853.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3532</th>\n",
       "      <td>外国</td>\n",
       "      <td>900000</td>\n",
       "      <td>1900.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3533 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          中文名  adcode  citycode\n",
       "0     中华人民共和国  100000       NaN\n",
       "1         北京市  110000      10.0\n",
       "2      北京市市辖区  110100      10.0\n",
       "3         东城区  110101      10.0\n",
       "4         西城区  110102      10.0\n",
       "5         朝阳区  110105      10.0\n",
       "6         丰台区  110106      10.0\n",
       "7        石景山区  110107      10.0\n",
       "8         海淀区  110108      10.0\n",
       "9        门头沟区  110109      10.0\n",
       "10        房山区  110111      10.0\n",
       "11        通州区  110112      10.0\n",
       "12        顺义区  110113      10.0\n",
       "13        昌平区  110114      10.0\n",
       "14        大兴区  110115      10.0\n",
       "15        怀柔区  110116      10.0\n",
       "16        平谷区  110117      10.0\n",
       "17        密云区  110118      10.0\n",
       "18        延庆区  110119      10.0\n",
       "19        天津市  120000      22.0\n",
       "20     天津市市辖区  120100      22.0\n",
       "21        和平区  120101      22.0\n",
       "22        河东区  120102      22.0\n",
       "23        河西区  120103      22.0\n",
       "24        南开区  120104      22.0\n",
       "25        河北区  120105      22.0\n",
       "26        红桥区  120106      22.0\n",
       "27        东丽区  120110      22.0\n",
       "28        西青区  120111      22.0\n",
       "29        津南区  120112      22.0\n",
       "...       ...     ...       ...\n",
       "3503      台湾省  710000    1886.0\n",
       "3504  香港特别行政区  810000    1852.0\n",
       "3505      中西区  810001    1852.0\n",
       "3506      湾仔区  810002    1852.0\n",
       "3507       东区  810003    1852.0\n",
       "3508       南区  810004    1852.0\n",
       "3509     油尖旺区  810005    1852.0\n",
       "3510     深水埗区  810006    1852.0\n",
       "3511     九龙城区  810007    1852.0\n",
       "3512     黄大仙区  810008    1852.0\n",
       "3513      观塘区  810009    1852.0\n",
       "3514      荃湾区  810010    1852.0\n",
       "3515      屯门区  810011    1852.0\n",
       "3516      元朗区  810012    1852.0\n",
       "3517       北区  810013    1852.0\n",
       "3518      大埔区  810014    1852.0\n",
       "3519      西贡区  810015    1852.0\n",
       "3520      沙田区  810016    1852.0\n",
       "3521      葵青区  810017    1852.0\n",
       "3522      离岛区  810018    1852.0\n",
       "3523  澳门特别行政区  820000    1853.0\n",
       "3524    花地玛堂区  820001    1853.0\n",
       "3525     花王堂区  820002    1853.0\n",
       "3526     望德堂区  820003    1853.0\n",
       "3527      大堂区  820004    1853.0\n",
       "3528     风顺堂区  820005    1853.0\n",
       "3529     嘉模堂区  820006    1853.0\n",
       "3530    路凼填海区  820007    1853.0\n",
       "3531   圣方济各堂区  820008    1853.0\n",
       "3532       外国  900000    1900.0\n",
       "\n",
       "[3533 rows x 3 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# adcode查询表\n",
    "\n",
    "import pandas as pd\n",
    "from IPython.display import display, HTML\n",
    "df = pd.read_excel('AMap_adcode_citycode_2020_4_10.xlsx',encoding=\"utf8\", sheet_name=\"Sheet1\")\n",
    "a = df.to_dict()\n",
    "dataframe = pd.DataFrame ( a )\n",
    "dataframe\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---------------------------------------------------------------------------------------------------\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 输入提示\n",
    "> 提供根据用户输入的关键词查询返回建议列表\n",
    "\n",
    "```python\n",
    "def search(keywords,datatype,location=None,type=None,city=None,citylimit=None,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'keywords':keywords,\n",
    "        'location':location,\n",
    "        'type':type,\n",
    "        'city':city,\n",
    "        'citylimit':citylimit,\n",
    "        'datatype':datatype,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "```\n",
    "\n",
    "* 【调用格式】：search(keywords='文字',datatype=all)\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| type | POI分类 |  |\n",
    "| location | 坐标 | 格式：“X,Y”（经度,纬度），不可以包含空格 |\n",
    "| city | 搜索城市 | 可选值：citycode、adcode |\n",
    "| citylimit | 仅返回指定城市数据 | 可选值：true/false |\n",
    "| datatype | 返回的数据类型 | 多种数据类型用“|”分隔，可选值：all-返回所有数据类型、poi-返回POI数据类型、bus-返回公交站点数据类型、busline-返回公交线路数据类型 |\n",
    "\n",
    "-----------------------------------------------------------\n",
    "------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 交通态势-圆形区域交通态势\n",
    "\n",
    "> 分为三种：矩形区域交通态势、圆形区域交通态势、指定线路交通态势\n",
    "\n",
    "```python\n",
    "def tfcondition(location,level,extensions,radius,sig=None)->dict:\n",
    "    url = 'https://restapi.amap.com/v3/traffic/status/rectangle?parameters'\n",
    "    params={\n",
    "        'key':key_chen,\n",
    "        'level':level,\n",
    "        'location':location,\n",
    "        'radius':radius,\n",
    "        'extensions':extensions,\n",
    "        'sig':sig,\n",
    "        'output':'json'\n",
    "    }\n",
    "    response = requests.get(url,params=params)\n",
    "    data = response.json()\n",
    "    return data\n",
    "\n",
    "```\n",
    "\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| level | 道路等级 | 1-6，5 |\n",
    "| extensions | 返回结果控制 | base/all,一般为base |\n",
    "| rectangle | 代表此为矩形区域查询 | 左下右上顶点坐标对,<=10km 坐标对用`;` 间隔 |\n",
    "| location | 圆形区域中心点坐标 | 经度在前，纬度在后。经度和纬度用`,`分割 |\n",
    "| radius | 半径 | 单位：米，最大取值5000米，一般为1000 |\n",
    "| name | 道路名 | 必填 |\n",
    "| city | 城市名 | 强烈建议使用adcode |\n",
    "| adcode | 城市编码 | city和adcode必填一个 |\n",
    "\n",
    "\n",
    "> 【**道路等级**】\n",
    ">> * 1：高速（京藏高速）\n",
    ">> * 2：城市快速路、国道(西三环、103国道)\n",
    ">> * 3：高速辅路（G6辅路）\n",
    ">> * 4：主要道路（长安街、三环辅路路）\n",
    ">> * 5：一般道路（彩和坊路）\n",
    ">> * 6：无名道路\n",
    "\n",
    "----------------------------------------\n",
    "----------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 总结·反思\n",
    "\n",
    "* 要熟读[API文档](https://lbs.amap.com/api/webservice/guide/api/grasproad)\n",
    "* 很多API调用需要`地理编码API`**获取地点坐标**进行定位\n",
    "\n",
    "> **旅游出行APP**\n",
    ">> * 【选择出行地点】输入提示 & 搜索POI & 静态地图——用户在搜索框搜索旅游区域，`输入提示API`自动出现在下拉的菜单中，当用户选中某一地点，`搜索POI API`显示该地点的信息（地点的名称、类型），地点附近的旅游点，帮助用户评估选择出行的地点，`静态地图API`可视化该地点，用户可看到旅游点的大概分布情况。  \n",
    ">> * 【规划出行路线】路径规划&交通态势——`路径规划API`和`交通态势API`相结合，为用户规划处一条最佳出行路线  \n",
    ">> * 【温馨提示】——`天气查询API`，在通过用户输入的地点进行天气查询和预告，让用户方便选择出行的衣物，如下雨天提示用户要记得带把伞"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Markdown语法：表格\n",
    "\n",
    "<div style='text-align : center;'>【代码释义】</div>\n",
    "\n",
    "| 参数名 | 含义 | 说明 |\n",
    "| :----:| :----: | :----: |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |\n",
    "| 单元格 | 单元格 | 单元格 |"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": false,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "281.331px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
